package com.fckbug.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fckbug.service.QAService;
import com.fckbug.util.SpringContextHolder;
import com.fckbug.vos.DetailVO;
import com.mysql.jdbc.StringUtils;

/**
 * 查询问题，问题地址无后缀.do
 * @author think
 *
 */
public class DetailServlet extends HttpServlet {
	private static final long serialVersionUID = -912920141748775867L;
	QAService qaService = (QAService)SpringContextHolder.getBean("qaService");
	public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
		String url = request.getRequestURI();
        String qId = url.substring(url.lastIndexOf("/") + 1);
        if(StringUtils.isNullOrEmpty(qId)) {
        	request.getRequestDispatcher("/error/404.jsp").forward(request, response);
        	return;
        }
		DetailVO result = qaService.getDetail(qId);
		if(result == null) {
			request.getRequestDispatcher("/error/404.jsp").forward(request, response);
			return;
		}
		qaService.alterQVTime(qId);
		request.setAttribute("detail", result);
		request.getRequestDispatcher("/question/detail.jsp").forward(request, response);
	}
}
